# Contributor: rubicon <rubicon@mailo.com>
# Maintainer: Celeste <cielesti@protonmail.com>
maintainer="Celeste <cielesti@protonmail.com>"
pkgname=ocaml-mew
_pkgname=mew
pkgver=0.1.0
pkgrel=3
pkgdesc="Modal editing witch"
url="https://github.com/kandu/mew"
arch="all !riscv64 !loongarch64" # ocaml
license="MIT"
depends_dev="$pkgname=$pkgver-r$pkgrel ocaml-trie-dev"
makedepends="$depends_dev dune ocaml"
options="!check"    # needs ppx_expect
subpackages="$pkgname-dev"
source="$pkgname-$pkgver.tar.gz::https://github.com/kandu/mew/archive/$pkgver.tar.gz
	use-built-in-result-lib.patch
	"
builddir="$srcdir/$_pkgname-$pkgver"
_ocamldir=usr/lib/ocaml

# 32-bit archs
case "$CARCH" in
	arm*|x86) options="$options textrels" ;;
esac

build() {
	dune build --release --verbose
}

check() {
	dune runtest --verbose
}

package() {
	dune install \
		--destdir="$pkgdir" \
		--docdir=/.omit
	rm -Rf "$pkgdir"/.omit
}

dev() {
	default_dev

	cd "$pkgdir"

	local path; find $_ocamldir \( \
			-name '*.cmt' -o \
			-name '*.cmti' -o \
			-name '*.ml' -o \
			-name '*.mli' \
		\) | while read -r path
	do
		amove "$path"
	done
}

prepare_py_provides() {
	local datadir="${subpkgdir:-$pkgdir}"
	local pkgbasedir=${pkgbasedir:-"$startdir/pkg"}
	local controldir="$pkgbasedir"/.control.${subpkgname:-$pkgname}

	options_has "!tracedeps" && return 0

	ocaml4-abuild-find provides \
		"$datadir"/usr/lib/ocaml \
		"$controldir" \
		"$pkgver-r$pkgrel"
}

scan_python3_dependency() {
	local controldir="$2" datadir="$3"

	ocaml4-abuild-find requires \
		"$datadir"/usr/lib/ocaml \
		"$controldir"
}

sha512sums="
77a68f6dc9f3edc729384d59247a29f32f969dc6d987ed2e6c88b9a64b655822dafa9c3cb424bf40e6cf9ed20cddf9c708738872db245f14a711770e8e938db3  ocaml-mew-0.1.0.tar.gz
b8bbfd9fc9281ad4463d060ba7941ed09516fb66a2b751213cd70094070e585f039bee0235012661eabfa28ba52ca011139c5def1457394bbe5fb9fb41e3d0b8  use-built-in-result-lib.patch
"
